import axios from "axios";
import { API_NAME, MATERIAL_NAME } from "./contants.ts";

const getAllChapterAPI = () => {
  return axios.get(`${API_NAME}/chapter/all`);
};

const getAllMaterialAPI = () => {
  return axios.get(`${API_NAME}/${MATERIAL_NAME}/all`);
};

const getMaterialByIDAPI = (id: number) => {
  return axios.get(`${API_NAME}/${MATERIAL_NAME}/info/${id}`);
};

const getAllVideoAPI = () => {
  return axios.get(`${API_NAME}/video/all`);
};

const getMaterialBySectionIDAPI = (id: number) => {
  return axios.get(`${API_NAME}/section/${id}/${MATERIAL_NAME}`);
};
const getVideoBySectionIDAPI = (id: number) => {
  return axios.get(`${API_NAME}/section/${id}/video`);
};

const getLatestVideoAPI = () => {
  return axios.get(`${API_NAME}/video/info/latest`);
};

const getVideoByIDAPI = (id: number) => {
  return axios.get(`${API_NAME}/video/info/${id}`);
};

const uploadMaterialAPI = (params: object) => {
  return axios.post(`${API_NAME}/${MATERIAL_NAME}/upload`, params, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
};

const updateMaterialAPI = (updatedMaterial: {
  id: number;
  title: string;
  section: number;
}) => {
  return axios.post(`${API_NAME}/${MATERIAL_NAME}/update`, updatedMaterial);
};

const updateVideoAPI = (updatedVideo: {
  id: number;
  title: string;
  section: number;
}) => {
  return axios.post(`${API_NAME}/video/update`, updatedVideo);
};

const deleteMaterialAPI = (id: number) => {
  return axios.post(`${API_NAME}/${MATERIAL_NAME}/delete/${id}`);
};

const deleteVideoAPI = (id: number) => {
  return axios.post(`${API_NAME}/video/delete/${id}`);
};

const uploadMaterialURL = `${API_NAME}/${MATERIAL_NAME}/upload`;

const uploadVideoURL = `${API_NAME}/video/upload`;

export {
  getAllChapterAPI,
  getAllMaterialAPI,
  getAllVideoAPI,
  getMaterialByIDAPI,
  getMaterialBySectionIDAPI,
  getVideoBySectionIDAPI,
  getVideoByIDAPI,
  uploadMaterialAPI,
  getLatestVideoAPI,
  uploadMaterialURL,
  uploadVideoURL,
  updateMaterialAPI,
  updateVideoAPI,
  deleteMaterialAPI,
  deleteVideoAPI,
};
